package com.ice.payment.controller;

import com.ice.payment.service.WxPayService;
import com.ice.payment.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author icewinters
 */
@CrossOrigin
@RestController
@RequestMapping("/api/wx-pay")
@Api(tags = "微信网站支付API")
@Slf4j
public class WxPayController {


    @Resource
    private WxPayService wxPayService;


    @ApiOperation("调用统一下单API，生成支付二维码")
    @PostMapping("native/{productId}")
    public R nativePay(@PathVariable Long productId) throws Exception {

        log.info("发起支付请求");

        // 返回支付二维码链接和订单号
        Map<String, Object> map = wxPayService.nativePay(productId);

        return R.ok().setData(map);
    }

}
